package com.hngy.scala

import org.apache.spark.{SparkConf, SparkContext}

/**
  * 使用集合创建RDD
  */
object CreateRddArrayScala {

  def main(args: Array[String]): Unit = {
    //创建sparkContext
    val conf = new SparkConf()
      conf.setAppName("CreateRddArrayScala")
      .setMaster("local")
    val sc = new SparkContext(conf)
    //创建集合
    val arr = Array(1,2,3,4,5)
    //基于集合创建RDD
    val rdd = sc.parallelize(arr)
    val sum = rdd.reduce(_ + _)
    println(sum)

    //停止sparkContext
    sc.stop()
  }
}
